package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/22 12:37 星期六<br/>
 * 此Transition会创建跨越其duration淡入淡出效果动画。
 * 这是通过定期更新node的opacity变量来完成的
 *
 * @author xuMingHai
 */
public class FadeTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);

        FadeTransition fadeTransition = new FadeTransition(Duration.millis(3000.0),
                rectangle);
        // from 起始值 to 最终值 by 起始值加by值
        fadeTransition.setToValue(0.5);
        fadeTransition.play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
